package com.podium.comment.utils;

/**
 * @author 邵文泽
 * @description 字符串工具类
 * @date 2025/4/24 17:57
 */
public class StringUtils extends org.springframework.util.StringUtils {


    /**
     * 将下划线命名转换为大驼峰命名法 PascalCase
     * @param underscoreStr 下划线命名的字符串
     * @return 驼峰命名的实体类名称
     */
    public static String toCamelCaseClassName(String underscoreStr) {
        if (underscoreStr == null || underscoreStr.isEmpty()) {
            return underscoreStr;
        }
        StringBuilder camelCaseStr = new StringBuilder(toCamelCase(underscoreStr));
        // 确保首字母大写
        if (!camelCaseStr.isEmpty()) {
            camelCaseStr.setCharAt(0, Character.toUpperCase(camelCaseStr.charAt(0)));
        }
        return camelCaseStr.toString();
    }

    /**
     * 将下划线命名转换为驼峰命名 camelCase
     * @param underscoreStr 下划线命名的字符串
     * @return 驼峰命名的字符串
     */
    public static String toCamelCase(String underscoreStr) {
        if (underscoreStr == null || underscoreStr.isEmpty()) {
            return underscoreStr;
        }

        StringBuilder camelCaseStr = new StringBuilder();
        boolean nextUpperCase = false;

        for (char c : underscoreStr.toCharArray()) {
            if (c == '_') {
                nextUpperCase = true;
            } else {
                if (nextUpperCase) {
                    camelCaseStr.append(Character.toUpperCase(c));
                    nextUpperCase = false;
                } else {
                    camelCaseStr.append(Character.toLowerCase(c));
                }
            }
        }

        return camelCaseStr.toString();
    }

}
